package com.monitor.action.user;

import java.io.PrintWriter;

import com.monitor.action.MonitorActionSupport;
import com.monitor.po.Contact;
import com.monitor.service.ContactService;
import com.monitor.util.Constants;
import com.monitor.util.Pager;

public class ContactAction extends MonitorActionSupport {

	private static final long serialVersionUID = 3550017289076190849L;
	private int cPage;
	Pager<Contact> contacts;
	private long uid;
	private ContactService contactService;
	private String cid;

	@Override
	public String execute() throws Exception {
		cPage = cPage < 1 ? 1 : cPage;
		long _uid = getUid(uid);
		contacts = contactService.getContactListByUid(_uid, Constants.DEFAULT_PAGESIEZE, cPage);
		return SUCCESS;
	}

	public void deleteContact() throws Exception {
		long _uid = getUid(uid);
		PrintWriter out = getWriter();
		boolean success = contactService.deleteContact(_uid, cid);
		if (success) {
			out.print("success");
		} else {
			out.print("failed");
		}
		out.flush();
		out.close();
	}

	public int getcPage() {
		return cPage;
	}

	public void setcPage(int cPage) {
		this.cPage = cPage;
	}

	public Pager<Contact> getContacts() {
		return contacts;
	}

	public void setContacts(Pager<Contact> contacts) {
		this.contacts = contacts;
	}

	public long getUid() {
		return uid;
	}

	public void setUid(long uid) {
		this.uid = uid;
	}

	public ContactService getContactService() {
		return contactService;
	}

	public void setContactService(ContactService contactService) {
		this.contactService = contactService;
	}

	public String getCid() {
		return cid;
	}

	public void setCid(String cid) {
		this.cid = cid;
	}

}
